/**
 * 定义OnlineMonitorController在线监测管理模块
 */
(function(window, angular, undefined){
	var OnlineMonitorController = angular.module('OnlineMonitorController', ['ui.router','itfreer','waterCommon','OperatorManagerService']);
		
	//设备资产管理控制器
	OnlineMonitorController.controller('DeviceManagerController',function($stateParams,OperationStationJobService,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$state,$formObject){
		//监控污水处理厂id变化
		if($wdp.viewValue.wwtpDetailParmWatch){
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			$scope.getDeviceLifeCycle();		
        },true);
		
		//接收子控制器传来的参数，点击触发
		$scope.$on('dataPramChanged', function(event, data) {
			$wdp.viewValue.wwtpDetailParm={};
			$wdp.viewValue.wwtpDetailParm.STATION_ID  = data.STATION_ID;
			$scope.getDeviceLifeCycle();
	    });
		var sessionId = $("#_sessionid").html();
		//监测点条件
		$scope.stationType = [];
		$scope.selectedStationtype= $stateParams.stationType || 'allType';
		if(getWaterType()=='0'){
			OperationStationJobService.postQuery("/Operation/getStationType.do",{}).then(function(data){
				angular.forEach(data.data,function(value,key){
					value.selected=false;
				});
				$scope.stationType =  data.data;
				$scope.stationType.splice(0,0,{S_DOMAINCODE:'allType',S_DOMAINCAPTION:'全部',selected:true})
			});
		}
		$scope.toggleStationType = function(row){
			if(row.S_DOMAINCODE==$scope.selectedStationtype) return;
			$scope.selectedStationtype=row.S_DOMAINCODE;
			$scope.getDeviceLifeCycle();
		}
		//是否退役条件
		$scope.selectedStationioos='all';
		$scope.stationIoos=[{NAME:"全部",CODE:"all"},{NAME:"退役",CODE:"1"},{NAME:"在役",CODE:"0"}];
		$scope.toggleStationIoos=function(row){
			if(row.CODE==$scope.selectedStationioos) return;
			$scope.selectedStationioos=row.CODE;
			$scope.getDeviceLifeCycle();
		}
		
		//查询站点设备资产管理信息
		$scope.getDeviceLifeCycle = function(){
			var wwtpId = $wdp.viewValue.wwtpDetailParm.WWTPID;
			var stationId = $wdp.viewValue.wwtpDetailParm.STATION_ID;
			if(!wwtpId && !stationId) return;
			$waterDataCommon.getPageRows("/OnlineMonitor/station.do","stationDetailList",{"WWTP_ID":wwtpId,"WATER_TYPE":'0',"BUILD_STATUS":'0'},10,1,function(d){
				//获取下拉所属站点数据
				$wdp.viewValue.StationDataForSelect={};
				$wdp.viewValue.StationDataForSelect.data=d.data;
			});
			var obj = {};
			obj.WWTP_ID=wwtpId;
			obj.STATION_ID=stationId;
			if($scope.selectedStationtype!='allType'){
				obj.FLOW_TYPE = $scope.selectedStationtype;
			}
			if($scope.selectedStationioos!='all'){
				obj.IS_OOS = $scope.selectedStationioos;
			}
			$waterDataCommon.getPageRows("/OnlineMonitor/getDeviceLifeCycleInfo.do","DeviceLifeCycleList",obj,10000,1,function(r){
				if(r && r.data){
					angular.forEach(r.data,function(value,key){
						if(!value.GUID){
							value.FIELD_ISNEW = true;
						}
					});
				}
			});
		};
		
		//编辑设备生命周期
		$scope.deviceCurRow = null;
		$scope.editDeviceLifeCycle = function(curRow){
			$scope.deviceCurRow = curRow;
			$scope.deviceObject = angular.copy(curRow);
			if(curRow.DEVICE_TYPE=='2'){
				$itfreer.openWindow('AssetsRegisterWin');
			}
			else{
				$itfreer.openWindow('deviceLifeCyleWin');
			}
			
		}
		
		//保存设备生命周期信息
		$scope.saveDeviceLifeCycle = function(){
			if($scope.deviceObject.IS_OOS=='1'){
				if(!$scope.deviceObject.OOS_DATE){
					$.messager.alert("提示","请选择退役日期！","info");
					return;
				}
				if(!$scope.deviceObject.OOS_REASON){
					$.messager.alert("提示","请填写退役原因！","info");
					return;
				}
			}
			
			$itfreerHttp.save('BC_DEVICE_LIFECYCLE',$scope.deviceObject,function(d){
				$scope.getDeviceLifeCycle();
				$itfreer.closeWindow('deviceLifeCyleWin');
				$.messager.alert("提示","保存成功","info");
			});	
		}
		//时间验证
		$scope.checkErr = function(){		   
		    if((new Date($scope.deviceObject.OENGING_DATE.replace(/-/g,"\/"))) > (new Date($scope.deviceObject.OOS_DATE.replace(/-/g,"\/")))){
		    	$.messager.alert("提示","启用时间不能大于退役时间");
		      return false;
		    }		 
		  };
		//查看设备维修记录
		$scope.showDeviceRepaireList = function(curRow){
			$wdp.viewValue.deviceNum = curRow.DEVICE_NUM;
			$state.go('DeviceManager.deviceRepair',{fromState:'DeviceManager.main',stationType:$scope.selectedStationtype});
			$scope.selectMenu('menuOperation1');
		};
		//新建设备资产登记
		$scope.newRgister=function(){
			$scope.deviceObject ={};
			$itfreer.openWindow('AssetsRegisterWin');
		};
		//保存登记信息
		$scope.saveRegister=function(){
			if($scope.checkErr()==false){
				return false;
			}
			if($scope.deviceObject.DEVICE_NUM!=undefined&&$scope.deviceObject.DEVICE_NUM!=null){
				if($scope.deviceObject.DEVICE_NUM.replace(/[^\w\.\/]/ig,"")==false){
					$.messager.alert("提示","设备编号只能输入数字或英文！");
					return;
				}
			}
			if($scope.deviceObject.NUM!=undefined&&$scope.deviceObject.NUM!=null){
				if($scope.deviceObject.NUM.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","报废数量只能输入数字！");
					return;
				}
			}
			$scope.deviceObject.WWTP_ID =$wdp.viewValue.wwtpDetailParm.WWTPID;
			$itfreerHttp.save('BC_DEVICE_LIFECYCLE',$scope.deviceObject,function(d){
				$itfreerHttp.save('BC_ASSETS_REGISTER',$scope.deviceObject,function(d){
					$scope.getDeviceLifeCycle();
					$itfreer.closeWindow('AssetsRegisterWin');
					$.messager.alert("提示","保存成功","info");
				});	
				
			});	
		};
		//删除登记信息
		$scope.deleteRegister=function(data){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_DEVICE_LIFECYCLE", {GUID:data.GUID},function(){
						$itfreerHttp.deleteByKey("BC_ASSETS_REGISTER", {DEVICE_NUM:data.DEVICE_NUM},function(){
							$.messager.alert("提示","删除成功！");
							$scope.getDeviceLifeCycle();
						});	
					});
									
				}
			});
		}
		
	});
	//污染源详情控制器：包括从站点地图和污染源信息
	OnlineMonitorController.controller('WsclcDetailController',function(OperationStationJobService,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$state,$formObject){
		$( "#WsclcDetailtabs" ).idTabs();
		var sessionId = $("#_sessionid").html();
		getAllYydw();
		
		//监控污水处理厂id变化
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			var WWTPID = $wdp.viewValue.wwtpDetailParm.WWTPID;
			$scope.getWsclcDetailExpNo(WWTPID);
			$scope.getStationListByWWTPID(WWTPID, "");
			var selectedTabName = $("#WsclcDetailtabs a.selected").attr("href");
			//如果当前选择的是污水处理厂，需要特殊处理，兼容站点地图模块
			if(selectedTabName == "#baxx"){
				if($("#wsclcXQTabLi").css("display") != "none"){
					$("#wsclcXQTabLi a").click();//如果是看污水处理厂信息，则切换到详情信息页
				}
				else{
					$("#wwtp_stationLi a").click();//如果是看站点信息，则切换到站点页
				}
			}
			else{
				$("#WsclcDetailtabs a.selected").click();
			}
			
        },true);
		
		$scope.editbaxx=function(str){
			 $wdp.viewValue.YydwDataForSelect["value"]="";
			 $wdp.viewValue.YydwDataForSelect.value=str;
			 $itfreer.openWindow("editbaxx");
		};
		$scope.editjbxx=function(){
			 $itfreer.openWindow("editjbxx");
		};
		$scope.editztxx=function(){
			var yearlist=$scope.yearlist={};
			yearlist.year=[];
			var nowDate = new Date();
			var y=nowDate.getFullYear();
			for(var i=0;i<6;i++){
				var obj=new Object();
				obj.name=y-i+"";
				obj.value=y-i+"";
				yearlist.year.push(obj);
			}; 
			 $scope.zxjcZtxx.NAME=nowDate.getFullYear()+"";
			 $itfreer.openWindow("edit_Ztxx");
		};
		$scope.cancel=function(type){
			if(type=="baxx")
			{
				$itfreer.closeWindow("editbaxx");
			}
			if(type=="jbxx")
			{
				$itfreer.closeWindow("editjbxx");
			}
			if(type=="ztxx")
			{
				$itfreer.closeWindow("edit_Ztxx");
			}
		};
		 var m
		//详情界面收合效果
		$("#baxx h5.wsclchead").bind("click",function(){
			var ishidden = $(this).next("div.wsclccontent").is(":hidden");
			 $("div.wsclccontent").slideUp();
			 if(ishidden){
				 $(this).next("div.wsclccontent").slideDown();
			 }
			 else{
				 $(this).next("div.wsclccontent").slideUp();
			 }
		 });
		//编辑页面折叠效果
		$scope.editSide = function(id){
			 var isedithidden = $("#"+id).next("div.editwsclccontent").is(":hidden");
			 $("div.editwsclccontent").slideUp();
			 if(isedithidden){
				 $("#"+id).next("div.editwsclccontent").slideDown();
			 }
			 else{
				 $("#"+id).next("div.editwsclccontent").slideUp();
			 }
		}
		
		$("#WsclcDetailtabs li a").bind("click",function(){
			var tabName = $(this).attr("href");
			var WWTPID = $wdp.viewValue.wwtpDetailParm.WWTPID;
			var stationExpNo = $wdp.viewValue.wwtpDetailParm.STATION_ID;
			if(tabName == "#DATA_COLLECTION_INSTRUMET"){
				//数采仪
				$scope.getScyDataByExpNo(WWTPID,stationExpNo);
				$scope.dataCollectionTab = true;
			}
			else if(tabName == "#zxjcsb"){
				//在线监测设备
				$scope.getSbxxDataByWsclsID(WWTPID,stationExpNo);
				$scope.sbxxTab = true;
			}
			else if(tabName == "#zxjczdwry"){
				//污染物
				$scope.getWryDataByExpNo(WWTPID,stationExpNo);
				$scope.WryTab = true;
			}
			else if(tabName == "#ztxx"){
				//国控状态信息
				$scope.queryWsclcZtxxList(WWTPID,stationExpNo);
				$scope.ztxxTab = true;
			}
			else if(tabName == "#Operations_unit"){
				//运营单位信息
				$scope.getYydwByName(WWTPID,stationExpNo);
				$scope.yydwTab = true;
			}
			else if(tabName == "#wwtp_station"){
				//站点信息
				$scope.getStationListByWWTPID(WWTPID,stationExpNo);
				$scope.stationTab = true;
			}
			else if(tabName == "#sbys"){
				$scope.getDeviceAcceptanceData(WWTPID,stationExpNo);
				$scope.sbysTab = true;
			}
			//视频信息
			else if(tabName == "#video"){
				$scope.getVideoData(WWTPID,stationExpNo);
				$scope.videoTab = true;
			}
			//门禁信息
			else if(tabName == "#access"){
				$scope.getAccessData(WWTPID,stationExpNo);
				$scope.videoTab = true;
			}
			//DVR信息
			else if(tabName == "#DVR"){
				$scope.getDVRData(WWTPID,stationExpNo);
				$scope.videoTab = true;
			}
			//中控数据
			else if(tabName == "#ControlData"){
				$scope.getControlData();
				$scope.ControlTab = true;
			}
		});
		$scope.queryObject={};
		$scope.queryObject.accessObj={};
		
		var now = new Date();
		 $scope.st=getOracleDateString(new Date(Date.parse(now) + (86400000 * -1)));
		 $scope.et=getOracleDateString(now);
		 function getOracleDateString(dtTmp){ 
				return dtTmp.getFullYear()+"-"+(dtTmp.getMonth()+1)+"-"+dtTmp.getDate();
			} 
		$scope.getControlData=function(){
			$scope.queryObject.WWTP_ID=$wdp.viewValue.wwtpDetailParm.WWTPID;
			$scope.queryObject.ST=$scope.st;
			$scope.queryObject.ET=$scope.et;
			$waterDataCommon.getPageRows("/ControlDataController/getControlData.do","ControlDataList",$scope.queryObject,1000,1,function(r){
			});
		};
		//获取门禁信息
		$scope.getAccessData=function(wwtpid,stationId){
			$scope.queryObject.accessObj.stationId=stationId;
			$scope.queryObject.accessObj.WWTP_ID=$wdp.viewValue.wwtpDetailParm.WWTPID;
			$waterDataCommon.getPageRows("/AccessController/getAccessDataById.do","AccessDataList",$scope.queryObject.accessObj,10,1,function(r){
				if(r){
					$scope.AccessDataList=r;
				}
			});
			
		};
		//新建门禁信息
		$scope.newAccess=function(){
			$scope.AccessData={};
			$itfreer.openWindow('newVideo');
		};
		//关闭门禁信息
		$scope.closeAccessData=function(){
			$itfreer.closeWindow('newVideo');
		};
		//编辑门禁信息
		$scope.editAccess=function(data){
			$scope.AccessData=data;
			$itfreer.openWindow('newVideo');
		}
		//删除门禁信息
		$scope.deleteAccess=function(data){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$waterDataCommon.getPageRows("/AccessController/deleteAccessData.do","AccessDataList",data,10,1,function(r){
						$.messager.alert("提示","删除成功！");
						$scope.getAccessData();
					});
					
				}
			});
		};
		
		//保存门禁信息
		$scope.saveAccessData=function(data){
			data.WWTPID=$wdp.viewValue.wwtpDetailParm.WWTPID;
			data.STATION_NAME=$("#accessSelect").find("option:selected").text();
			$waterDataCommon.getPageRows("/AccessController/savaAccessData.do","AccessDataList",data,10,1,function(r){
				$itfreer.closeWindow('newVideo');
				$.messager.alert("提示","保存成功！");
				$scope.getAccessData();
			});
		};
		
		$scope.VideoPosition=[{value:"0",name:"站房内"},{value:"1",name:"采样点"}];
		//获取视频信息
		$scope.getVideoData=function(wwtpid,stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getVideoData.do?sessionId="+sessionId,"videoList",{"WWTP_ID":wwtpid,"STATION_ID":stationId},10,1,function(d){
				
			});
		}
		//判断更新还是保存视频信息
		$scope.isVideoUpdata=false;
		//新建视频信息
		$scope.newVideo=function(){
			$scope.VideoData={};
			$itfreer.openWindow('editVideo');
		};
		//关闭新建视频信息
		$scope.closeVideoData=function(){
			$itfreer.closeWindow('editVideo');
		};
		//保存视频信息
		$scope.saveVideoData=function(VideoData){
			 if(VideoData.IP){
				 $itfreerHttp.save('BC_VIDEO_INFO',VideoData,function(d){
						$scope.getVideoData($wdp.viewValue.wwtpDetailParm.WWTPID,"");
						$itfreer.closeWindow('editVideo');
						$.messager.alert("提示","保存成功");
					}); 
			 }
			 else{
				 $.messager.alert("提示","未录入任何相关信息，无法保存！");
			 }	
		};
		//编辑视频信息
		$scope.editViedo=function(data){
			$scope.VideoData=angular.copy(data);
			$itfreer.openWindow('editVideo');
		}
		//删除视频信息
		$scope.deleteVideo=function(data){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_VIDEO_INFO", {GUID:data.GUID},function(){
						$.messager.alert("提示","删除成功！");
						$scope.getVideoData($wdp.viewValue.wwtpDetailParm.WWTPID,"");
					});
				}
			});
		};
		
		//获取DVR信息
		$scope.getDVRData=function(wwtpid,stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getDVRData.do","DVRList",{"WWTP_ID":wwtpid,"STATION_ID":stationId},10,1,function(d){
				
			});
		}
		//新建DVR信息
		$scope.newDVR=function(){
			$scope.DVRData={};
			$itfreer.openWindow('editDVR');
		};
		//关闭新建DVR信息
		$scope.closeDVRData=function(){
			$itfreer.closeWindow('editDVR');
		};
		//保存DVR信息
		$scope.saveDVRData=function(Data){
			var arr = Object.keys(Data);
				if(arr.length>0){
					$itfreerHttp.save('BC_DVR_INFO',Data,function(d){
						$scope.getDVRData($wdp.viewValue.wwtpDetailParm.WWTPID,"");
						$itfreer.closeWindow('editDVR');
						$.messager.alert("提示","保存成功");
					});
				 }
				 else{
					 $.messager.alert("提示","未录入任何相关信息，无法保存！");
				 }	
		};
		//编辑DVR信息
		$scope.editDVR=function(data){
			$scope.DVRData=angular.copy(data);
			$itfreer.openWindow('editDVR');
		}
		//删除DVR信息
		$scope.deleteDVR=function(data){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_DVR_INFO", {GUID:data.GUID},function(){
						$.messager.alert("提示","删除成功！");
						$scope.getDVRData($wdp.viewValue.wwtpDetailParm.WWTPID,"");
					});
				}
			});
		};
		
		//获取运营单位
		$scope.getYydwByName=function(wwtpid,stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getOperationUnitByWWTPID.do","zxjcYydw",{"WWTP_ID":wwtpid,"STATION_ID":stationId},2,1,function(d){
				$wdp.viewValue.zxjcYydw=d.data[0];
			});
		};
		
		//获取污水厂所属监测站点
		$scope.getStationListByWWTPID = function(wwtpId,stationId){
			//如果污水厂和站点条件都为空，不查询
			if(!wwtpId && !stationId) return;
			
			var waterType = getWaterType();
			
			$waterDataCommon.getPageRows("/OnlineMonitor/station.do","stationDetailList",{"WWTP_ID":wwtpId,"STATION_ID":stationId,"WATER_TYPE":waterType,"BUILD_STATUS":'0'},10,1,function(d){
				//获取下拉所属站点数据
				$wdp.viewValue.StationDataForSelect={};
				$wdp.viewValue.StationDataForSelect.data=d.data;
			});
		}
		
		//获取数采仪数据
		$scope.getScyDataByExpNo=function(wwtpId,stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getDataCollectionInstrument.do","scyList",{"WWTP_ID":wwtpId,"STATION_ID":stationId},10,1);
		};
		
		//获取在线监测设备信息
		$scope.getSbxxDataByWsclsID=function(wwtpId,stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getMonitorEquipment.do","sbxxList",{"WWTP_ID":wwtpId,"STATION_ID":stationId},10,1);
		};
		
		//获取站点污染物数据
		$scope.showPollList = function(deviceRow){
			$scope.selectDeviceId = deviceRow.GUID
			$waterDataCommon.getPageRows("/OnlineMonitor/getWryDataByExpNo.do","wryList", {"deviceId":deviceRow.GUID},10,1);
			$itfreer.openWindow('pollList', {title:"污染物信息",width:820,high:900});
		}
		
		//查询污水处理厂（监控）状态信息
		$scope.queryWsclcZtxxList=function(wwtpId,stationId){	
			$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",{"WWTP_EXP_NO:like":wwtpId,"STATION_ID":stationId},20,1);
		};
		
		//获取所有运营单位数据
		 function getAllYydw(){
			$.ajax({
				url:getBasePath() + "/OnlineMonitor/getOperationUnit.do",
				dataType : 'json',
				success:function(d){
					$wdp.viewValue.YydwDataForSelect={};
					$wdp.viewValue.YydwDataForSelect.data=d.data;
				}
			});
		};
		
		//保存污水处理厂数据
		$scope.saveWsclcData=function(str,isinvalid){
			var wsclcdata=$wdp.viewValue.path;
			if(wsclcdata.EXP_NO==null)
			{
				wsclcdata.EXP_NO=wsclcdata.SDEEXP_NO;
			}
			if(wsclcdata.ATTENTION_LEVEL_DESC==null||wsclcdata.ATTENTION_LEVEL_DESC==""){
				wsclcdata.ATTENTION_LEVEL="";
			}
			for(var key in wsclcdata){
				if(wsclcdata[key] == null){
					delete wsclcdata[key];
				}
			}
			wsclcdata.OPERATOR=$wdp.viewValue.YydwDataForSelect.value;
			wsclcdata.tableName = "BC_ENTERPRISE_ATTR";
			wsclcdata.FIELD_ISNEW=false;
			//wsclcdata.COMPANY_CODE=wsclcdata.EXP_NO;
			wsclcdata.GUID=wsclcdata.EXP_NO;
			wsclcdata.NAME=wsclcdata.SDENAME;
			 $.ajax({
				 	url : getBasePath()+'/OnlineMonitor/updateWsclc.do',
					type : 'POST',
					data : wsclcdata,
					success : function(d){
						if(str=="baxx")
						{
							$itfreer.closeWindow("editbaxx");
						}
						if(str=="jbxx")
						{
							$itfreer.closeWindow("editjbxx");
						}
						$.messager.alert("提示","保存成功!");
						$scope.getWsclcDetailExpNo(wsclcdata.EXP_NO);
						$scope.getYydwByName(wsclcdata.EXP_NO);
					}
				});
			};
			
			//获取污水处理厂详情
			$scope.getWsclcDetailExpNo=function(eno){
				$waterDataCommon.getPageRows("/OnlineMonitor/wsclcDetail.do","dataw",{Exp_No:eno},10,1,function(data){
					if(data.data.length < 1){
						$wdp.viewValue.path = {};
						return;
					}
					var obj=data.data[0];
					 var url=obj.IMG;
					 var arr = new Array();
					 if(url!=""&&url!=null){
						 if(url.indexOf("|") > 0)
							{
								 arr = url.split("|");
								 obj.IMGURL=getHostBase()+String(arr[arr.length-1].toString().split(":")[0]);
						    }
							 else{
								 arr = url.split(":");
								 obj.IMGURL=getHostBase()+String(arr[0]);
							 }
					 }
					 else{
						 obj.IMGURL=getHostBase()+"wdp/images/noPic.png"; 
					 }
					 if(obj.EXP_NO==null)
					  {
						 obj.EXP_NO= obj.SDEEXP_NO;
					  }
					 if(obj.OBJECTID==null)
					  {
						 obj.OBJECTID=obj.SDEOBJECTID
					  }
					$wdp.viewValue.path=obj;
				},null,null,true);
			};
			/*新增站点*/
			$scope.addStation=function(){
				$itfreer.openWindow('add_Station');
			};
			//保存站点信息
			$scope.saveStation = function(station){
				station.WWTP_ID = $wdp.viewValue.path.EXP_NO;
				station.EXP_NO= station.CODE;
				station.tableName = "BC_SITE_INFO";
				$waterDataCommon.post("/Data/Create",station,function(d){
					$scope.getStationListByWWTPID($wdp.viewValue.path.EXP_NO, "");
					$itfreer.closeWindow('add_Station');
			        $.messager.alert("提示","保存成功","info");
				});
			};
			
			/*关闭新建站点窗口*/
			$scope.closeAddStationWnd=function(){
				$itfreer.closeWindow('add_Station');
			};
			$scope.station={};
			//打开站点详情
			$scope.showStationDetail = function(station){
				$scope.stationImgs={};
				$scope.station=station;
				if(station.EVN_PHOTO){
					var imgsInfos = station.EVN_PHOTO.split("|");
					if(imgsInfos.length != 0){
						for(var i=0;i<imgsInfos.length;i++){
							imgsInfos[i] = getBasePath()+"/"+imgsInfos[i].split(":")[0];
						}
						
						$scope.stationImgs = imgsInfos;
					}
				}
				$itfreer.openWindow('detail_Station',{title:"站点详情",width:800,high:500});
			};
			$scope.stationEdit={};
			//打开站点编辑界面
			$scope.showStationEdit = function(station){
				$scope.stationEdit=angular.copy(station);
				$itfreer.openWindow('edit_Station',{title:"编辑站点",width:800,high:540});
			};
			
			//保存站点信息
			$scope.updateStation = function(station){
				station.tableName = "BC_SITE_INFO";
				 var phone=station.OPERATION_PHONE;
				 if(phone){
					if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(phone)){
						 $.messager.alert("提示","电话号码有误","info");
						return false; 
				   } 
				 }
				 
				$waterDataCommon.post("/Data/Update",station,function(d){
					$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
					$itfreer.closeWindow('edit_Station');
			        $.messager.alert("提示","保存成功","info");
				});
			};
			
			//关闭站点变价窗口
			$scope.closeStationWnd = function(){
				$itfreer.closeWindow('edit_Station');
			};
			
			//查看站点地图
			$scope.showStationInMap=function(data){
				$.ajax({
					url:getBasePath() + "/OnlineMonitor/getStationGeoByExpNo.do?EXP_NO="+data.EXP_NO,
					dataType : 'json',
					success:function(d){
						$waterDataCommon.AddWktFeaturesToMap(d,null,null,true);
					}
				});
				$formObject.isMIS = false;
				$wdp.viewValue.showBackToMisBtn = true;
				setTimeout(function() {
					$wdp.widowResizeEventHandler();
				}, 200);
			};
		
			$scope.zxjcZtxx = {};
			$scope.zxjcZtxx.isAdd = false;
			
			//查询污水处理厂（监控）状态信息
			$scope.queryWsclcZtxxList=function(){	
				$queryObj.WsclcZtxxQueryObj = {"WWTP_EXP_NO:like":$wdp.viewValue.path.EXP_NO};
				$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1);
			};
			
			//保存污水处理厂（监控）状态信息
			$scope.saveZxjcZtxx=function(zxjcZtxx,valid){
				$scope.zxjcZtxx.WWTP_EXP_NO=$wdp.viewValue.path.EXP_NO;
				$scope.startChecked = true;
				$scope.zxjcZtxx.isAdd = true;
				if(!valid){
					return;
				}
				if(!($waterDataCommon.judgmentDate(zxjcZtxx.START_DATE,zxjcZtxx.END_DATE))){
					$.messager.alert("提示","结束日期不能小于开始日期");
					return;
				}
				
				$itfreerHttp.save('WWTP_ATTENTION',zxjcZtxx,function(){					
					$itfreer.closeWindow("edit_Ztxx");
					$.messager.alert("提示","保存成功");
					if($scope.zxjcZtxx.isAdd){
						$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1,function(){
							$waterDataCommon.lastPage($httpData.ztxxList,$queryObj.WsclcZtxxQueryObj);
						});			
					}
				});			
			};
			
			//打开命令配置窗口
			$scope.openOrderList=function(row){
				$scope.deviceId = row.GUID;
				$waterDataCommon.getPageRows("/RemoteControl/getDeviceOrderByDeviceid.do","orderList",{"deviceId":row.GUID},10,1,function(result){});
				$itfreer.openWindow('orderList',{title:"设备命令配置"});
			};
			
			//保存命令配置
			$scope.saveDeviceOrders = function(datas){
				var orders = "";
				var deviceId = $scope.deviceId;
				
				for(i in datas){
					var row = datas[i];
					if(row.ISCHECKED == "1"){
						orders += row.S_DOMAINCODE+",";
					}
				}
				$waterDataCommon.post("/RemoteControl/updateDeviceOrders.do",{"deviceId":deviceId,"orders":orders},function(d){
					$.messager.alert("提示","保存成功","info");
					$itfreer.closeWindow('orderList');
				});
			}
			
			//关闭状态信息窗口
			$scope.closeZxjcZtxx=function(){
				$itfreer.closeWindow("edit_Ztxx");
			}
					
			//删除污水处理厂(监控)状态   
			$scope.deleteZxjcztxx=function(zxjcZtxx){
				$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
					if(r){
						$itfreerHttp.deleteByKey("WWTP_ATTENTION",{GUID:zxjcZtxx.GUID},function(){
							$.messager.alert("提示","删除成功！");
							$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1);	
						});
					}
				});
			};
			/**数采仪使用方法 start**/
			//控制保存按钮显示与否
			$scope.isShowSave=true;
			//新建数采仪信息
			$scope.newSCY=function(){
				$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
				$scope.isShowSave=true;
				$scope.startChecked = false;
				$scope.ScyData={};
				$scope.ScyData.WSCLC_ID=$wdp.viewValue.path.EXP_NO;
				$itfreer.openWindow('add_Scy');
			};
			//保存数采仪信息
			$scope.saveScyData=function(ScyData,isinvalid){
				$scope.startChecked = true;
				if(!isinvalid){
					return;
				}
				var phone1=ScyData.OPERATION_NUM;
				var phone2=ScyData.MANUFACTURER_NUM
				 if(phone1){
					//if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ 
					if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(phone1)){
						 $.messager.alert("提示","运维单位联系电话有误","info");
						return false; 
				   } 
				 }
				if(phone2){
					//if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ 
					if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(phone2)){
						 $.messager.alert("提示","生产厂商联系电话有误","info");
						return false; 
				   } 
				 }
				//ScyData.OPERATION_UNIT=$wdp.viewValue.YydwDataForSelect.value;
				 $itfreerHttp.save('BC_COLLECTION_INFO',ScyData,function(d){
					$scope.getScyDataByExpNo(ScyData.WSCLC_ID);
					$itfreer.closeWindow('add_Scy');
					$.messager.alert("提示","保存成功");
				});
			};
			//关闭新建窗口
			$scope.closeAddScyData=function(){
				$itfreer.closeWindow('add_Scy');
			};
			//获取数采仪名称
			$scope.getName=function(str){
				$scope.startChecked=false;
				var data=$wdp.viewValue.StationDataForSelect.data;
				for(var i=0;i<data.length;i++){
					var obj=data[i];
					if(obj.EXP_NO==str)
					{
						$scope.ScyData.ID=obj.NAME+"数据采集仪";
					}
				}
			};
			
			//获取设备验收数据
			$scope.acceptData={};
			$scope.isShowAcceptDataSave=true;
			$scope.isShowReAccept=false;
			$scope.isShowAccept=false;
			$queryObj.deviceAcceptQueryObj={"WSCLC_ID":"","stationCode":""};
			
			$scope.getDeviceAcceptanceData = function(WWTPID,stationExpNo){
				var wwtp_id = WWTPID || $wdp.viewValue.wwtpDetailParm.WWTPID;
				var station_id = stationExpNo || $wdp.viewValue.wwtpDetailParm.STATION_ID;
				getStationList(wwtp_id,station_id);
			};
			
			$scope.refreshAcceptData = function(stationCode){
				$("li[stationCode]").removeClass("selected");
				$("li[stationCode='"+stationCode+"']").addClass("selected");
				$queryObj.deviceAcceptQueryObj.stationCode = stationCode;
				getAcceptData();
			}
			
			function getStationList(wwtpId,stationExpNo){
				if(!wwtpId && !stationExpNo){
					return;
				}
				
				$queryObj.deviceAcceptQueryObj.WSCLC_ID = wwtpId;
				$queryObj.deviceAcceptQueryObj.stationCode = stationExpNo;
//				$queryObj.deviceAcceptQueryObj.flowType='1';
				
				$waterDataCommon.getPageRows("/OnlineMonitor/getStationCodeList.do","stationListPS",$queryObj.deviceAcceptQueryObj,10,1,function(result){
					if(result.data == null || result.data.length < 1){
						$queryObj.deviceAcceptQueryObj.stationCode = "NONE";
					}else{
						$queryObj.deviceAcceptQueryObj.stationCode=result.data[0].CODE;
						
						$("li[stationCode]").removeClass("selected");
						$("li[stationCode='"+$queryObj.deviceAcceptQueryObj.stationCode+"']").addClass("selected");
					}
					getAcceptData();
				});
			}
			
			function getAcceptData(){
				$waterDataCommon.getPageRows("/OnlineMonitor/getDeviceAcceptanceData.do","deviceAcceptanceList",$queryObj.deviceAcceptQueryObj,10,1,function(result){
					if(result.acceptData!=null && result.acceptData.length>0){
						$scope.isShowReAccept = true;
						$scope.isShowAccept = false;
					}
					else{
						
						$scope.isShowReAccept = false;
						$scope.isShowAccept = true;
					}
				});
			};
			
			//设备验收
			$scope.newAcceptInfo=function(){
				$scope.startChecked = false;
				var dtTmp = new Date();
				var dateStr = dtTmp.getFullYear()+"-"+(dtTmp.getMonth()+1)+"-"+dtTmp.getDate();
				$scope.acceptData={"ACCEP_DATE":dateStr,
						"STATUS":"1",
						"WSCLC_ID":$queryObj.deviceAcceptQueryObj.WSCLC_ID,
						"STATION_CODE":$queryObj.deviceAcceptQueryObj.stationCode};
				$scope.isShowAcceptDataSave = true;
				$itfreer.openWindow("acceptDevice");
			};
			//设备验收信息查看
			$scope.showAcceptInfo=function(obj,editable){
				$scope.acceptData = angular.copy(obj);
				$scope.isShowAcceptDataSave = editable;
				$itfreer.openWindow("acceptDevice");
			};
			//删除验收信息
			$scope.delAcceptInfo=function(obj){
				$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
					if(r){
						$itfreerHttp.deleteByKey("BC_DEVICE_ACCE_INFO", {GUID:obj.GUID},function(){
							$.messager.alert("提示","删除成功！","info");
							$scope.getDeviceAcceptanceData();
						})
					}
				});
			};
			//查看验收记录
			$scope.showAcceptList = function(){
				$itfreer.openWindow("acceptDeviceList");
			};
			
			//保存设备验收信息
			$scope.saveAcceptInfo=function(isinvalid){
				$scope.startChecked = true;
				if(!isinvalid){
					return;
				}
				 $itfreerHttp.save('BC_DEVICE_ACCE_INFO',$scope.acceptData,function(data){
						$scope.getDeviceAcceptanceData();
						$itfreer.closeWindow('acceptDevice');
						$.messager.alert("提示","保存成功","info");
					}
				 );
			};
			
			//打开详情
			$scope.openDetail=function(derailData){
				$scope.isShowSave=false
				$scope.ScyData=derailData;
				$itfreer.openWindow('show_Scy',{title:"数采仪详情",width:1040,high:350});
			};
			//编辑信息
			$scope.editScy=function(editdata){
				$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
				$scope.isShowSave=true;
				$scope.ScyData=angular.copy(editdata);
				$itfreer.openWindow('add_Scy',{title:"编辑数采仪信息",width:1040,high:350});
			};
			//删除信息
			$scope.deleteScy=function(daletedata){
				$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
					if(r){
						$itfreerHttp.deleteByKey("BC_COLLECTION_INFO", {GUID:daletedata.GUID},function(){
							$.messager.alert("提示","删除成功！","info");
							$scope.getScyDataByExpNo(daletedata.WSCLC_ID);
						});
					}
				});
			};
			/**数采仪使用方法 end**/
			
			/**在线监测设备使用方法 start**/
			//控制保存按钮显示与否
			$scope.isShowSbxxSave=true;
			$scope.SbxxData={};
			
			//打开在线监测设备详情
			$scope.openSbxxDetail=function(detailData){
				$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
				$scope.SbxxData=detailData;
				$itfreer.openWindow('detail_Sbxx',{title:"设备详情",width:820,high:900});
			};
			//编辑在线监测设备信息
			$scope.editSbxx=function(editdata){
				$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
				$scope.SbxxData=angular.copy(editdata);
				$itfreer.openWindow('add_Sbxx',{title:"编辑设备",width:820,high:900});
			};
			//删除在线监测设备信息
			$scope.deleteSbxx=function(daletedata){
				$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
					if(r){
						$itfreerHttp.deleteByKey("BC_SITE_DEVICE_RPT", {GUID:daletedata.GUID},function(){
							$.messager.alert("提示","删除成功！");
							$scope.getSbxxDataByWsclsID(daletedata.WSCLC_ID);
						});
					}
				});
			};
			
			//新建在线监测设备信息
			$scope.newsbxx=function(){
				$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
				$scope.startChecked=false;
				$scope.SbxxData={};
				$scope.SbxxData.WSCLC_ID=$wdp.viewValue.path.EXP_NO;
				$itfreer.openWindow('add_Sbxx', {title:"新建设备",width:820,high:900});
			};
			
			//保存在线监测设备信息
			$scope.saveSbxxData=function(SbxxData, valid){
				//SbxxData.MONITOR_POINT=$wdp.viewValue.StationDataForSelect.value;
				$scope.startChecked = true;
				if(!valid){
					return;
				}
				
				$itfreerHttp.save('MONITOR_EQUIPMENT',SbxxData,function(d){
					$scope.getSbxxDataByWsclsID(SbxxData.WSCLC_ID);
					$itfreer.closeWindow('add_Sbxx');
					$.messager.alert("提示","保存成功");
				});	
			};
			
			//关闭在线监测设备信息
			$scope.closeAddSbxxData=function(){
				$itfreer.closeWindow('add_Sbxx');
			};
			
			//改变监测设备站点信息
			$scope.changeSbxxName=function(station_expno){
				$scope.startChecked=false;
				var station=$wdp.viewValue.StationDataForSelect.data;
				var station_name = "";
				
				for(var i=0;i<station.length;i++){
					if(station[i].EXP_NO==station_expno){
						station_name=station[i].NAME;
					}
				}
				
				var domain = $waterDataCommon.getDomainByModelName("SbxxData.MONITOR_POLLUTANTS");
				var pollution_name = domain[$scope.SbxxData.MONITOR_POLLUTANTS];
				$scope.SbxxData.NAME=station_name+"-"+pollution_name;
			}
			
			/**在线监测设备使用方法 end**/
			
			/**站点污染物使用方法 start**/
			//控制保存按钮显示与否
			$scope.isShowWrySave=true;
			$scope.WryData={};
			//新建站点污染物信息
			$scope.newWry=function(deviceId){
				$scope.WryData={};
				if(deviceId != null){
					$scope.WryData.DEVICE_ID = deviceId;
				}
				$scope.getStationListByWWTPID($wdp.viewValue.wwtpDetailParm.WWTPID,$wdp.viewValue.wwtpDetailParm.STATION_ID);
				$scope.isShowWrySave=true;
				$scope.startChecked = false;
				$scope.WryData.WSCLC_ID=$wdp.viewValue.path.EXP_NO;
				
				$itfreer.openWindow('add_Wry');
			};
			$scope.percent=[{VALUE:"5",NAME:"5"},{VALUE:"7",NAME:"7"},{VALUE:"10",NAME:"10"},{VALUE:"15",NAME:"15"},{VALUE:"20",NAME:"20"}]
			//保存站点污染物信息
			$scope.saveWryData=function(WryData,isinvalid){
				$scope.startChecked = true;
				if(!isinvalid){
					return;
				}
				$itfreerHttp.save('SITE_POLLUTANTS',WryData,function(d){
					$scope.getWryDataByExpNo(WryData.WSCLC_ID);
					$itfreer.closeWindow('add_Wry');
					$.messager.alert("提示","保存成功");
				});
			};
			//关闭新建窗口
			$scope.closeAddWryData=function(){
				$itfreer.closeWindow('add_Wry');
			};
			//打开详情
			$scope.openwryDetail=function(derailData){
				$scope.WryData=angular.copy(derailData);
				$itfreer.openWindow('show_Wry',{title:"污染物详情",width:1040,high:350});
			};
			//编辑信息
			$scope.editwry=function(editdata){
				$scope.isShowWrySave=true;
				$scope.WryData=angular.copy(editdata);
				$itfreer.openWindow('add_Wry',{title:"编辑污染物信息",width:1040,high:350});
			};
			$scope.closeadd_Wry=function(){
				//清空新增集合
				$scope.WryData=[];
				$itfreer.closeWindow('add_Wry');
			};
			//删除信息
			$scope.deletewry=function(daletedata){
				$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
					if(r){
						$itfreerHttp.deleteByKey("BC_SITE_POLL", {GUID:daletedata.GUID},function(){
							$.messager.alert("提示","删除成功！");
							$scope.getWryDataByExpNo(daletedata.WSCLC_ID);
						});
					}
				});
			};
			//打开设置关注度
			$scope.openLevelData=function(){
				$queryObj.WsclcZtxxQueryObj = {"WWTP_EXP_NO:like":$wdp.viewValue.path.EXP_NO};
				$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1);
				$itfreer.openWindow('GetStatusList');
			};
			//设置关注度
			$scope.getLevelData=function(val){
				$wdp.viewValue.path.ATTENTION_LEVEL_DESC=val.TYPE_DESC;
				$wdp.viewValue.path.ATTENTION_LEVEL=val.TYPE;
				$itfreer.closeWindow("GetStatusList");
			};
			$scope.waterDataCommon = $waterDataCommon;	
			//获取站点污染物数据
			$scope.getWryDataByExpNo=function(wwtpId,stationId,deviceId){
				$waterDataCommon.getPageRows("/OnlineMonitor/getWryDataByExpNo.do","wryList", {"WWTP_ID":wwtpId,"STATION_ID":stationId,"deviceId":deviceId,"waterType":getWaterType()},10,1);
			};
	});
	
	//站点信息控制器
	OnlineMonitorController.controller('StationDetailController',function($sce,
			$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,
			$queryObj,$wdp,$rootScope,$state,$formObject,OperationStationJobService){
		$scope.STATION_ID = "";
		$scope.WryData={};
		$( "#StationDetailtabs" ).idTabs();
		var sessionId = $("#_sessionid").html();
		getAllYydw();
		$scope.percent=[{VALUE:"5",NAME:"5"},{VALUE:"7",NAME:"7"},{VALUE:"10",NAME:"10"},{VALUE:"15",NAME:"15"},{VALUE:"20",NAME:"20"}];
		
		$scope.$on('dataPramChanged', function(event, data) {
			$scope.STATION_ID = data.STATION_ID;
			$("#StationDetailtabs a.selected").click();
	    });
		
		//编辑状态信息：国控，省控等
		$scope.editztxx=function(){
			var yearlist=$scope.yearlist={};
			yearlist.year=[];
			var nowDate = new Date();
			var y=nowDate.getFullYear();
			for(var i=0;i<6;i++){
				var obj=new Object();
				obj.name=y-i+"";
				obj.value=y-i+"";
				yearlist.year.push(obj);
			}; 
			 $scope.zxjcZtxx.NAME=nowDate.getFullYear()+"";
			 $itfreer.openWindow("edit_Ztxx");
		};
		
		$scope.cancel=function(type){
			if(type=="ztxx")
			{
				$itfreer.closeWindow("edit_Ztxx");
			}
		};
		
		$("#StationDetailtabs li a").bind("click",function(){
			var tabName = $(this).attr("href");

			if(!$scope.STATION_ID) return;
			
			var stationExpNo = $scope.STATION_ID;
			
			if(tabName == "#dciList"){
				//数采仪
				$scope.getScyDataByExpNo(stationExpNo);
				$scope.dataCollectionTab = true;
			}
			else if(tabName == "#equipmentList"){
				//在线监测设备
				$scope.getSbxxDataByWsclsID(stationExpNo);
				$scope.pollShow=false;
				$scope.sbxxTab = true;
			}
			else if(tabName == "#pollutantList"){
				//污染物
				if(getWaterType()=='3'||getWaterType()=='7'){
					$scope.getStationDetail(stationExpNo);
					$scope.getWryDataByExpNo(stationExpNo);
					$scope.pollShow=true;
					$scope.WryTab = true;
				}else{					
					$scope.getStationDetail(stationExpNo);
					$scope.getStationWryAlarmInfoByExpNo(stationExpNo);
					$scope.WryTab = true;
				}
			}
			else if(tabName == "#Operations_unit"){
				//运营单位信息
				$scope.getYydwByName(stationExpNo);
				$scope.yydwTab = true;
			}
			else if(tabName == "#stationList"){
				//站点信息
				$scope.getStationDetail(stationExpNo);
				$scope.stationTab = true;
			}
			else if(tabName == "#deviceAcceptList"){
				//设备验收
				$scope.getDeviceAcceptanceData(stationExpNo);
				$scope.sbysTab = true;
			}
		});
		
		//获取运营单位
		$scope.getYydwByName=function(stationExpNo){
			$waterDataCommon.getPageRows("/OnlineMonitor/getOperationUnitByStationID.do","zxjcYydw",{"STATION_ID":stationExpNo},2,1,function(d){
				$wdp.viewValue.zxjcYydw=d.data[0]
			});
		};
		//供水获取站点污染物数据
		$scope.getWryDataByExpNo=function(stationId,deviceId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getWryDataByExpNo.do","wryList", {"STATION_ID":stationId,"deviceId":deviceId,"waterType":getWaterType()},10,1);
		};
		//获取站点详情信息
		$scope.getStationDetail = function(stationId){
			if(!stationId) return;
			$waterDataCommon.getPageRows("/OnlineMonitor/station.do","stationDetailList",{"STATION_ID":stationId},10,1,function(d){
				//获取下拉所属站点数据
				$wdp.viewValue.StationDataForSelect={};
				$wdp.viewValue.StationDataForSelect.data=d.data;
			});
		}
		
		//获取数采仪数据
		$scope.getScyDataByExpNo=function(stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getDataCollectionInstrument.do","scyList",{"STATION_ID":stationId},10,1);
		};
		
		//获取在线监测设备信息
		$scope.getSbxxDataByWsclsID=function(stationId){
			$waterDataCommon.getPageRows("/OnlineMonitor/getMonitorEquipment.do","sbxxList",{"STATION_ID":stationId},10,1);
		};
		$scope.stationPollAlarmData={};
		//获取站点污染物数据
		$scope.stationID="";
		$scope.getStationWryAlarmInfoByExpNo=function(stationId,deviceId){
			$scope.stationID=stationId;
			$waterDataCommon.getPageRows("/OnlineMonitor/getStationWryAlarmInfoByExpNo.do","wryList", {"STATION_ID":stationId,"deviceId":deviceId,"waterType":getWaterType()},10,1,function(data){
				$scope.stationPollAlarmData.data = data.data;
				$scope.stationPollAlarmData.MN = data.data[0].MN;
			});
		};
		/***************站点信息所用方法如下START*********************/		
		$scope.station={};
		//打开站点详情
		$scope.showStationDetail = function(station){
			$scope.stationImgs={};
			$scope.station=station;
			if(station.EVN_PHOTO){
				var imgsInfos = station.EVN_PHOTO.split("|");
				if(imgsInfos.length != 0){
					for(var i=0;i<imgsInfos.length;i++){
						imgsInfos[i] = imgsInfos[i].split(":")[0];
					}
					
					$scope.stationImgs = imgsInfos;
				}
			}
			$itfreer.openWindow('detail_Station',{title:"站点详情",width:800,high:500});
		};
			
		//打开站点编辑界面
		$scope.showStationEdit = function(station){
			$scope.stationEdit=angular.copy(station);
			$itfreer.openWindow('edit_Station',{title:"编辑站点",width:800,high:540});
		};
			
		//保存站点信息
		$scope.updateStation = function(station){
			 if(station.OPERATION_PHONE){
					if(!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(station.OPERATION_PHONE)){
						 $.messager.alert("提示","电话号码有误","info");
						return false; 
				   } 
				 }
			station.tableName = "BC_SITE_INFO";
			$waterDataCommon.post("/Data/Update",station,function(d){
				$scope.getStationDetail(station.CODE);
				$itfreer.closeWindow('edit_Station');
		        $.messager.alert("提示","保存成功","info");
			});
		};
	
		//关闭站点编辑窗口
		$scope.closeStationWnd = function(){
			$itfreer.closeWindow('edit_Station');
		};
/***************站点信息所用方法如下END*********************/	
			
		$scope.zxjcZtxx = {};
		$scope.zxjcZtxx.isAdd = false;
			
		//查询污水处理厂（监控）状态信息
		$scope.queryWsclcZtxxList=function(){	
			$queryObj.WsclcZtxxQueryObj = {"WWTP_EXP_NO:like":$wdp.viewValue.path.EXP_NO};
			$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1);
		};
			
		//保存污水处理厂（监控）状态信息
		$scope.saveZxjcZtxx=function(zxjcZtxx,valid){
			$scope.zxjcZtxx.WWTP_EXP_NO=$wdp.viewValue.path.EXP_NO;
			$scope.startChecked = true;
			$scope.zxjcZtxx.isAdd = true;
			if(!valid){
				return;
			}
			
			$itfreerHttp.save('WWTP_ATTENTION',zxjcZtxx,function(){					
				$itfreer.closeWindow("edit_Ztxx");
				$.messager.alert("提示","保存成功");
				if($scope.zxjcZtxx.isAdd){
					$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1,function(){
						$waterDataCommon.lastPage($httpData.ztxxList,$queryObj.WsclcZtxxQueryObj);
					});			
				}
			});			
		};
		
		//打开命令配置窗口
		$scope.openOrderList=function(row){
			$scope.deviceId = row.GUID;
			$waterDataCommon.getPageRows("/RemoteControl/getDeviceOrderByDeviceid.do","orderList",{"deviceId":row.GUID},10,1,function(result){});
			$itfreer.openWindow('orderList',{title:"设备命令配置"});
		};
		
		//保存命令配置
		$scope.saveDeviceOrders = function(datas){
			var orders = "";
			var deviceId = $scope.deviceId;
			
			for(i in datas){
				var row = datas[i];
				if(row.ISCHECKED == "1"){
					orders += row.S_DOMAINCODE+",";
				}
			}
			$waterDataCommon.post("/RemoteControl/updateDeviceOrders.do",{"deviceId":deviceId,"orders":orders},function(d){
				$.messager.alert("提示","保存成功","info");
				$itfreer.closeWindow('orderList');
			});
		}
		
		//关闭状态信息窗口
		$scope.closeZxjcZtxx=function(){
			$itfreer.closeWindow("edit_Ztxx");
		}
		//删除污水处理厂(监控)状态   
		$scope.deleteZxjcztxx=function(zxjcZtxx){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("WWTP_ATTENTION",{GUID:zxjcZtxx.GUID},function(){
						$.messager.alert("提示","删除成功！");
						$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1);	
					});
				}
			});
		};
	
		/**数采仪使用方法 start**/
		//控制保存按钮显示与否
		$scope.isShowSave=true;
		//新建数采仪信息
		$scope.newSCY=function(){
			$scope.getStationDetail($scope.STATION_ID);
			$scope.isShowSave=true;
			$scope.startChecked = false;
			$scope.ScyData={};
			$itfreer.openWindow('add_Scy');
		};
		//保存数采仪信息
		$scope.saveScyData=function(ScyData,isinvalid){
			if($scope.validationRules(ScyData)==false){
				return false;
			}else{
				$scope.startChecked = true;
				if(!isinvalid){
					return;
				}
				//ScyData.OPERATION_UNIT=$wdp.viewValue.YydwDataForSelect.value;
				 $itfreerHttp.save('BC_COLLECTION_INFO',ScyData,function(d){
					$scope.getScyDataByExpNo(ScyData.SITE_ID);
					$itfreer.closeWindow('add_Scy');
					$.messager.alert("提示","保存成功");
				});
			}
		};
		//关闭新建窗口
		$scope.closeAddScyData=function(){
			$itfreer.closeWindow('add_Scy');
		};
		//获取数采仪名称
		$scope.getName=function(str){
			$scope.startChecked=false;
			var data=$wdp.viewValue.StationDataForSelect.data;
			for(var i=0;i<data.length;i++){
				var obj=data[i];
				if(obj.EXP_NO==str)
				{
					$scope.ScyData.ID=obj.NAME+"数据采集仪";
				}
			}
		};
		//打开详情
		$scope.openDetail=function(derailData){
			$scope.ScyData=derailData;
			$itfreer.openWindow('show_Scy',{title:"数采仪详情",width:1040,high:350});
		};
		//输入效验
		$scope.validationRules=function(station){
			var date=new Date();
			dateDay=date.getFullYear() + "-"+ (date.getMonth()+1) + "-" + date.getDate()+ " 00:00:00";
			if(station.OENGING_DATE!=undefined&&station.OENGING_DATE!=""){
				if(station.OENGING_DATE>dateDay){
					$.messager.alert("提示","启用日期不能大于当前日期");
					return false;
				}
			}
			if(station.OPERATION_NUM!=undefined&&station.OPERATION_NUM!=""){
				if(station.OPERATION_NUM.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","运维单位联系电话有误！");
					return false;
				}
			 }
			if(station.MANUFACTURER_NUM!=undefined&&station.MANUFACTURER_NUM!=""){
				if(station.MANUFACTURER_NUM.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","生产厂商联系电话有误！");
					return false;
				}
			 }
			if(station.DEVICE_NUM!=undefined&&station.DEVICE_NUM!=""){
				if(station.DEVICE_NUM.replace(/[^\w\.\/]/ig,"")==false){
					$.messager.alert("提示","设备出厂编号只能输入数字或字母！");
					return false;
				}
			}
			if(station.LICENSE_NUM!=undefined&&station.LICENSE_NUM!=""){
				if(station.LICENSE_NUM.replace(/[^\w\.\/]/ig,"")==false){
					$.messager.alert("提示","生产许可编号只能输入数字或字母！");
					return false;
				}
			}
			if(station.ENVIRONMENT_NUM!=undefined&&station.ENVIRONMENT_NUM!=""){
				if(station.ENVIRONMENT_NUM.replace(/[^\w\.\/]/ig,"")==false){
					$.messager.alert("提示","环保产品认证编号只能输入数字或字母！");
					return false;
				}
			}
			if(station.EQUIPMENT_TYPE!=undefined&&station.EQUIPMENT_TYPE!=""){
				if(station.EQUIPMENT_TYPE.replace(/[^\w\.\/]/ig,"")==false){
					$.messager.alert("提示","设备型号只能输入数字或字母！");
					return false;
				}
			}
			if(station.NUM_AISLE_SUM!=undefined&&station.NUM_AISLE_SUM!=""){
				if(station.NUM_AISLE_SUM.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","数字输入通道数量只能输入数字！");
					return false;
				}
			}
			if(station.SIMULATION_AISLE_SUM!=undefined&&station.SIMULATION_AISLE_SUM!=""){
				if(station.SIMULATION_AISLE_SUM.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","模拟量输入通道数量只能输入数字！");
					return false;
				}
			}
			if(station.SWITCH_AISLE_SUM!=undefined&&station.SWITCH_AISLE_SUM!=""){
				if(station.SWITCH_AISLE_SUM.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","开关量输入通道数量只能输入数字！");
					return false;
				}
			}
			if(station.STORAGE_CAPACITY!=undefined&&station.STORAGE_CAPACITY!=""){
				if(station.STORAGE_CAPACITY.replace(/[^0-9]/g,"")==false){
					$.messager.alert("提示","存储容量只能输入数字！");
					return false;
				}
			}
			
		}
		//编辑信息
		$scope.editScy=function(editdata){
			$scope.getStationDetail($scope.STATION_ID);
			$scope.isShowSave=true;
			$scope.ScyData=angular.copy(editdata);
			$itfreer.openWindow('add_Scy',{title:"编辑数采仪信息",width:1040,high:350});
		};
		//删除信息
		$scope.deleteScy=function(daletedata){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_COLLECTION_INFO", {GUID:daletedata.GUID},function(){
						$.messager.alert("提示","删除成功！","info");
						$scope.getScyDataByExpNo(daletedata.SITE_ID);
					});
				}
			});
		};
		/**数采仪使用方法 end**/
			
		//获取设备验收数据
		$scope.acceptData={};
		$scope.isShowAcceptDataSave=true;
		$scope.isShowReAccept=false;
		$scope.isShowAccept=false;
		$queryObj.deviceAcceptQueryObj={"WSCLC_ID":"","stationCode":""};
			
		$scope.getDeviceAcceptanceData = function(stationId){
			var station_id = stationId;
			getStationList(station_id);
		};
			
		$scope.refreshAcceptData = function(stationCode){
			$("li[stationCode]").removeClass("selected");
			$("li[stationCode='"+stationCode+"']").addClass("selected");
			$queryObj.deviceAcceptQueryObj.stationCode = stationCode;
			getAcceptData();
		}
			
		function getStationList(stationExpNo){
			if(!stationExpNo){
				return;
			}
			
			$queryObj.deviceAcceptQueryObj.stationCode = stationExpNo;
			
			$waterDataCommon.getPageRows("/OnlineMonitor/getStationCodeList.do","stationListPS",$queryObj.deviceAcceptQueryObj,10,1,function(result){
				if(result.data == null || result.data.length < 1){
					$queryObj.deviceAcceptQueryObj.stationCode = "NONE";
				}else{
					$queryObj.deviceAcceptQueryObj.stationCode=result.data[0].CODE;
					
					$("li[stationCode]").removeClass("selected");
					$("li[stationCode='"+$queryObj.deviceAcceptQueryObj.stationCode+"']").addClass("selected");
				}
				getAcceptData();
			});
		}
			
		function getAcceptData(){
			$waterDataCommon.getPageRows("/OnlineMonitor/getDeviceAcceptanceData.do","deviceAcceptanceList",$queryObj.deviceAcceptQueryObj,10,1,function(result){
				if(result.acceptData!=null && result.acceptData.length>0){
					$scope.isShowReAccept = true;
					$scope.isShowAccept = false;
				}
				else{
					
					$scope.isShowReAccept = false;
					$scope.isShowAccept = true;
				}
			});
		};
		//设备验收
		$scope.newAcceptInfo=function(){
			$scope.startChecked = false;
			var dtTmp = new Date();
			var dateStr = dtTmp.getFullYear()+"-"+(dtTmp.getMonth()+1)+"-"+dtTmp.getDate();
			$scope.acceptData={"ACCEP_DATE":dateStr,
					"STATUS":"1",
					"WSCLC_ID":$queryObj.deviceAcceptQueryObj.WSCLC_ID,
					"STATION_CODE":$queryObj.deviceAcceptQueryObj.stationCode};
			$scope.isShowAcceptDataSave = true;
			$itfreer.openWindow("acceptDevice");
		};
		//设备验收信息查看
		$scope.showAcceptInfo=function(obj,editable){
			$scope.acceptData = angular.copy(obj);
			$scope.isShowAcceptDataSave = editable;
			$itfreer.openWindow("acceptDevice");
		};
		//删除验收信息
		$scope.delAcceptInfo=function(obj){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_DEVICE_ACCE_INFO", {GUID:obj.GUID},function(){
						$.messager.alert("提示","删除成功！","info");
						$scope.getDeviceAcceptanceData(obj.STATION_CODE);
					})
				}
			});
		};
		//查看验收记录
		$scope.showAcceptList = function(){
			$itfreer.openWindow("acceptDeviceList");
		};
		//保存设备验收信息
		$scope.saveAcceptInfo=function(isinvalid){
			$scope.startChecked = true;
			if(!isinvalid){
				return;
			}
			 $itfreerHttp.save('BC_DEVICE_ACCE_INFO',$scope.acceptData,function(data){
					$scope.getDeviceAcceptanceData($scope.acceptData.STATION_CODE);
					$itfreer.closeWindow('acceptDevice');
					$.messager.alert("提示","保存成功","info");
				}
			 );
		};
			
		/**在线监测设备使用方法 start**/
		//控制保存按钮显示与否
		$scope.isShowSbxxSave=true;
		$scope.SbxxData={};
		
		//打开在线监测设备详情
		$scope.openSbxxDetail=function(detailData){
			$scope.getStationDetail($scope.STATION_ID);
			$scope.SbxxData=detailData;
			$itfreer.openWindow('detail_Sbxx',{title:"设备详情",width:820,high:900});
		};
		//编辑在线监测设备信息
		$scope.editSbxx=function(editdata){
			$scope.getStationDetail($scope.STATION_ID);
			$scope.SbxxData=angular.copy(editdata);
			$itfreer.openWindow('add_Sbxx',{title:"编辑设备",width:820,high:900});
		};
		//删除在线监测设备信息
		$scope.deleteSbxx=function(daletedata){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_SITE_DEVICE_RPT", {GUID:daletedata.GUID},function(){
						$.messager.alert("提示","删除成功！");
						$scope.getSbxxDataByWsclsID(daletedata.MONITOR_POINT);
					});
				}
			});
		};
		//新建在线监测设备信息
		$scope.newsbxx=function(){
			$scope.getStationDetail($scope.STATION_ID);
			$scope.startChecked=false;
			$scope.SbxxData={};
			$itfreer.openWindow('add_Sbxx', {title:"新建设备",width:820,high:900});
		};
		//保存在线监测设备信息
		$scope.saveSbxxData=function(SbxxData, valid){
			if($scope.validationRules(SbxxData)==false){
				return;
			}
			$scope.startChecked = true;
			if(!valid){
				return;
			}
			
			$itfreerHttp.save('MONITOR_EQUIPMENT',SbxxData,function(d){
				$scope.getSbxxDataByWsclsID(SbxxData.MONITOR_POINT);
				$itfreer.closeWindow('add_Sbxx');
				$.messager.alert("提示","保存成功");
			});	
		};
		//打开设备下面的污染物信息
		$scope.showPollList = function(deviceRow){
			$scope.selectDeviceId = deviceRow.GUID
			$waterDataCommon.getPageRows("/OnlineMonitor/getPollutantsByDeviceId.do","wryList", {"deviceId":deviceRow.GUID},10,1);
			$itfreer.openWindow('pollList', {title:"污染物信息",width:820,high:900});
		}
		
		//关闭在线监测设备信息
		$scope.closeAddSbxxData=function(){
			$itfreer.closeWindow('add_Sbxx');
		};
		
		//改变监测设备站点信息
		$scope.changeSbxxName=function(station_expno){
			$scope.startChecked=false;
			var station=$wdp.viewValue.StationDataForSelect.data;
			var station_name = "";
			
			for(var i=0;i<station.length;i++){
				if(station[i].EXP_NO==station_expno){
					station_name=station[i].NAME;
				}
			}
			
			var domain = $waterDataCommon.getDomainByModelName("SbxxData.MONITOR_POLLUTANTS");
			var pollution_name = domain[$scope.SbxxData.MONITOR_POLLUTANTS];
			$scope.SbxxData.NAME=station_name+"-"+pollution_name;
		}
		//获取所有运营单位数据
		 function getAllYydw(){
			$.ajax({
				url:getBasePath() + "/OnlineMonitor/getOperationUnit.do?sessionId="+sessionId,
				dataType : 'json',
				success:function(d){
					$wdp.viewValue.YydwDataForSelect={};
					$wdp.viewValue.YydwDataForSelect.data=d.data;
				}
			});
		};
		/**在线监测设备使用方法 end**/
		
		/**站点污染物使用方法 start**/
		//控制保存按钮显示与否
		$scope.isShowWrySave=true;
		//新建站点污染物信息
		$scope.newWry=function(deviceId){
			$scope.WryData={};
			if(deviceId != null){
				$scope.WryData.DEVICE_ID = deviceId;
			}
			$scope.getStationDetail($scope.STATION_ID);
			$scope.isShowWrySave=true;
			$scope.startChecked = false;
			$itfreer.openWindow('add_Wry');
		};
		
		//保存站点污染物信息
		$scope.saveWryData=function(WryData,isinvalid){
			$scope.startChecked = true;
			if(!isinvalid){
				return;
			}
			$itfreerHttp.save('SITE_POLLUTANTS',WryData,function(d){				
				if($scope.pollShow==false){
					$scope.getWryDataByExpNo(WryData.SITE_ID,WryData.DEVICE_ID);
				}else{
					$scope.getWryDataByExpNo(WryData.SITE_ID);
				}	
				$itfreer.closeWindow('add_Wry');
				$.messager.alert("提示","保存成功");
			});
		};
		//打开详情
		$scope.openwryDetail=function(derailData){
			$scope.WryData=derailData;
			$itfreer.openWindow('show_Wry',{title:"污染物详情",width:1040,high:350});
		};
		//编辑信息
		$scope.editwry=function(editdata){
			$scope.isShowWrySave=true;
			$scope.WryData=angular.copy(editdata);
			$scope.getStationDetail();
			$itfreer.openWindow('add_Wry',{title:"编辑污染物信息",width:1040,high:350});
		};
		//删除信息
		$scope.deletewry=function(daletedata){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("BC_SITE_POLL", {GUID:daletedata.GUID},function(){
						$.messager.alert("提示","删除成功！");
						if($scope.pollShow==false){
							$scope.getWryDataByExpNo(daletedata.SITE_ID,daletedata.DEVICE_ID);
						}else{
							$scope.getWryDataByExpNo(daletedata.SITE_ID);
						}	
					});
				}
			});
		};
		$scope.closeadd_Wry=function(){
			//清空新增集合
			$scope.WryData=[];
			$itfreer.closeWindow('add_Wry');
		};
		//打开设置关注度
		$scope.openLevelData=function(){
			$queryObj.WsclcZtxxQueryObj = {"WWTP_EXP_NO:like":$wdp.viewValue.path.EXP_NO};
			$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",$queryObj.WsclcZtxxQueryObj,20,1);
			$itfreer.openWindow('GetStatusList');
		};
		//设置关注度
		$scope.getLevelData=function(val){
			$wdp.viewValue.path.ATTENTION_LEVEL_DESC=val.TYPE_DESC;
			$wdp.viewValue.path.ATTENTION_LEVEL=val.TYPE;
			$itfreer.closeWindow("GetStatusList");
		};
		$scope.waterDataCommon = $waterDataCommon;	
		//根据站点和污染物查询的阈值，角色，用户数据
		$scope.PollAlarmThresholdList={};
		//最终入库的数据对象
		$scope.pollAlarmThredAndRoleUserData={};
		/**
		 * 当前指派的污染物阈值对象（单条阈值）
		 */
		$scope.currentAssignPollAlarmItem = null;
		/**
		 * 当前编辑的污染物
		 */
		$scope.currentEditPoll = null;
		/**
		 * 全选和全不选按钮的切换
		 */
		$scope.isShowRole='false';
		$scope.isShowUser='true';
		/**
		 * 编辑污染物阈值
		 */
		$scope.onEditPollClick = function(editData){
			$scope.IsShowRoleUser='false';
			$scope.IsShowAlarmThreshold='true';
			var queryObj = {
				'STATION_ID':$scope.stationID,
				'pollCode':editData.POLLCODE
			};
			$waterDataCommon.getPageRows("/OnlineMonitor/getPollAlarmDetail.do","PollAlarmThresholdList", queryObj,100,1,function(data) {
				$scope.currentEditPoll = data.data;
				if($scope.currentEditPoll.length==1) {
					$scope.currentEditPoll[0].ALARM_THRED_NUM="阈值 1";
				}
			});
			$itfreer.openWindow('add_poll_alarm_thred',{title:"编辑污染物信息",width:650,high:350});
		}
		/**
		 * 新增阈值按钮
		 */
		$scope.onAddNewPollAlarmClick = function(editPoll){
			var object={
					"ALARM_THRED_NUM":"阈值  "+(parseInt(editPoll.length)+parseInt(1))
			}
			editPoll.push(object);
		}
		/**
		 * 选择增加用户
		 */
		$scope.onUserChange = function(pollAlarmItem,user,isCheck){
			if(user.selected){
				if(pollAlarmItem.users) {
					if(pollAlarmItem.users.indexOf(user,'USERID') < 0){
						pollAlarmItem.users.push(user);
					}
				} else {
					pollAlarmItem.users=[];
					pollAlarmItem.users.push(user);
				}
			}
			else{
				pollAlarmItem.users.remove(user,'USERID');
			}
		}
		/**
		 * 选择增加角色
		 */
		$scope.onRoleChange = function(pollAlarmItem,role){
			$scope.roleList;
			if(role.selected){
				if(pollAlarmItem.roles) {
					if(pollAlarmItem.roles.indexOf(role,'ROLEID') < 0){
						pollAlarmItem.roles.push(role);
					}
				} else {
					pollAlarmItem.roles=[];
					pollAlarmItem.roles.push(role);
				}
			} else {
				pollAlarmItem.roles.remove(role,'ROLEID');
			}
			//角色变化的时候，已设置用户那里也要对应改变
			if(pollAlarmItem.roles==null||pollAlarmItem.roles.length==0) {
				$scope.currentAssignPollAlarmItem.users=null;
			}
			var roles="";
			for(var i=0;i<$scope.roleList.length;i++) {
				var selecte=$scope.roleList[i].selected;
				var roleid = $scope.roleList[i].ROLEID;
				if(selecte==true) {
						roles+=roleid+",";
				}
			}
			$waterDataCommon.getPageRows("/OnlineMonitor/getTheUserOfRole.do","roleList", {"role":roles},100,1,function(data){
				//查询结果,更新用户
				 $scope.userList = data.data;
			});
		}
		/**
		 * 角色全选按钮
		 */
		$scope.selectAllRole = function() {
			$scope.isShowRole='true';
			var roles="";
			for(var i=0;i<$scope.roleList.length;i++) {
				$scope.roleList[i].selected=true;
				$scope.onRoleChange($scope.currentAssignPollAlarmItem,$scope.roleList[i],true);
				var role = $scope.roleList[i].ROLEID;
				if(role) {
					roles+=role+",";
				}
			}
			$waterDataCommon.getPageRows("/OnlineMonitor/getTheUserOfRole.do","roleList", {"role":roles},100,1,function(data){
				//查询结果,更新用户
				 $scope.userList = data.data;
			});
		}
		/**
		 * 角色全不选按钮
		 */
		$scope.cancelAllRole = function() {
			$scope.isShowRole='false';
			$scope.currentAssignPollAlarmItem.roles=null;
			$scope.currentAssignPollAlarmItem.users=null;
			for(var i=0;i<$scope.roleList.length;i++) {
				$scope.roleList[i].selected=false;
				$scope.userList =null;
			}
			
		}
		/**
		 * 用户全选按钮
		 */
		$scope.selectAllUser = function() {
			$scope.isShowUser='false';
			for(var i=0;i<$scope.userList.length;i++) {
				$scope.userList[i].selected=true;
				$scope.onUserChange($scope.currentAssignPollAlarmItem,$scope.userList[i],true);
			}
		}
		/**
		 * 用户全不选按钮
		 */
		$scope.cancelAllUser = function() {
			$scope.isShowUser='true';
			for(var i=0;i<$scope.userList.length;i++) {
				$scope.userList[i].selected=false;
				$scope.onUserChange($scope.currentAssignPollAlarmItem,$scope.userList[i],false);
			}
			$scope.currentAssignPollAlarmItem.isClearAllUser=true;
		}
		/**
		 * 指派按钮
		 */
		$scope.onAssignAlarmClick = function(pollAlarmItem){
			$scope.IsShowRoleUser='true';
			$scope.IsShowAlarmThreshold='false';
			$scope.currentAssignPollAlarmItem = pollAlarmItem;
			
			$scope.roleList = [];
			$scope.userList = [];
			
			$scope.currentAssignPollAlarmItem.roles = [];
			$scope.currentAssignPollAlarmItem.users = [];
			var queryObj = {
				alarm_guid:pollAlarmItem.ALARMGUID
			};
			$waterDataCommon.getPageRows("/OnlineMonitor/getAlarmRoleAndUserSet.do","roleUserList", queryObj,100,1,function(data){
				$scope.allRoleUserList = data.data;
				//[0]代表的是该条记录的角色和用户
				//[1]代表的是所有的角色
				//[2]代表的是所有的用户
				$scope.currentAssignPollAlarmItem.roles=$scope.allRoleUserList[0];
				$scope.currentAssignPollAlarmItem.users=$scope.allRoleUserList[1];
				 $scope.roleList = $scope.allRoleUserList[2];
				 $scope.userList = $scope.allRoleUserList[3];
				 	 if($scope.currentAssignPollAlarmItem.roles) {
				 	 	for(var j=0;j<$scope.currentAssignPollAlarmItem.roles.length;j++) {
				 	 		var roleID=$scope.currentAssignPollAlarmItem.roles[j].ROLEID;
				 	 		for(var i=0;i<$scope.roleList.length;i++) {
				 	 			var roid = $scope.roleList[i].ROLEID;
					 	 		if(roid==roleID) {
					 	 			$scope.roleList[i].selected=true;
					 	 		}
				 	 		}
				 	 	}
				 	 }
					 var roledd="";
					 if($scope.currentAssignPollAlarmItem.roles) {
					 	for(var i=0;i<$scope.currentAssignPollAlarmItem.roles.length;i++) {
								roledd+=$scope.currentAssignPollAlarmItem.roles[i].ROLEID+",";
					 	}
					 }
					$waterDataCommon.getPageRows("/OnlineMonitor/getTheUserOfRole.do","roleList", {"role":roledd},100,1,function(data){
						//查询结果,更新用户
						 $scope.userList = data.data;
					 	 if($scope.currentAssignPollAlarmItem.users!=null) {
					 	 	for(var i=0;i<$scope.currentAssignPollAlarmItem.users.length;i++) {
					 	 		var userid = $scope.currentAssignPollAlarmItem.users[i].USERID;
					 	 		for(var j=0;j<$scope.userList.length;j++) {
					 	 			var userID = $scope.userList[j].USERID;
					 	 			if(userid==userID) {
					 	 				$scope.userList[j].selected=true;
					 	 			}
					 	 		}
					 	 	}
					 	 }
					});
			});
		}
		/**
		 * 保存污染物
		 */
		$scope.onSavePollClick = function(editData){
			var mn = editData[0].DEVICE_NUM;
			var pollCode = editData[0].NAME;
			//组装数据进行入库操作
			for(var k=0;k<editData.length;k++) {
				var guid = editData[k].ALARMGUID;
				var users = editData[k].users;
				for(var j=0;j<$scope.stationPollAlarmData.data[0].length;j++) {
					var GUID = $scope.stationPollAlarmData.data[0][j].GUID;
					var userId = $scope.stationPollAlarmData.data[0][j].USERNAME;
					if(guid==GUID&&userId!=null&&!users) {
						editData[k].users=[];
						var userIdArray = userId.split(",");
						for(var kk=0;kk<userIdArray.length;kk++) {
							var id = userIdArray[kk];
							var userobject={
								"USERID":id,
								"USER_NAME":null
							}
							editData[k].users.push(userobject);
						}
					}
				}

			}
			var stationPollAlarmData={};
			var roleAndUserData="";
			for(var i=0;i<editData.length;i++) {
				var users = "";
				var userData = editData[i].users;
				if(userData) {
					for(var k=0;k<userData.length;k++) {
						var user=userData[k].USERID;
						if(user) {
							users += user+",";
						}else {
							users +=",";
						}
					}
				}
				var station_id = editData[i].SITE_ID;
				var poll_code = editData[i].NAME;
				var GUID = editData[i].ALARMGUID;
				var MN = editData[i].DEVICE_NUM;
				var DENSITY_ALARM_DOWMLIMIT = editData[i].DENSITY_ALARM_DOWMLIMIT;
				var DENSITY_ALARM_UPLIMIT = editData[i].DENSITY_ALARM_UPLIMIT;
				var ALARM_THRED_NUM = "阈值 "+parseInt(i+1);
				var isClearAllUser=editData[i].isClearAllUser;
				roleAndUserData+="ALARM_NAME:"+ALARM_THRED_NUM+";"
								+"DENSITY_ALARM_DOWMLIMIT:"+DENSITY_ALARM_DOWMLIMIT+";"
								+"DENSITY_ALARM_UPLIMIT:"+DENSITY_ALARM_UPLIMIT+";"
								+"USERS:"+users+";"
								+"isClearAllUser:"+isClearAllUser+";";
				if(GUID != null){
					roleAndUserData += "GUID:"+GUID+";"
				}
				roleAndUserData += "@";
			}
			
			stationPollAlarmData.alarmSets=roleAndUserData;
			stationPollAlarmData.site_id=$scope.stationID;
			stationPollAlarmData.mn=mn;
			stationPollAlarmData.pollCode=pollCode;
			stationPollAlarmData.ABNORMAL_MIN=editData[0].ABNORMAL_MIN;
			stationPollAlarmData.ABNORMAL_MAX=editData[0].ABNORMAL_MAX;
			stationPollAlarmData.ABNORMAL_ALARM_DOWN=editData[0].ABNORMAL_ALARM_DOWN;
			stationPollAlarmData.ABNORMAL_ALARM_UP=editData[0].ABNORMAL_ALARM_UP;
			
			$waterDataCommon.post("/OnlineMonitor/savePollAlarmInfo.do", stationPollAlarmData,function(data){
				$scope.getStationWryAlarmInfoByExpNo($scope.stationID);
				$itfreer.closeWindow('add_poll_alarm_thred');
				$.messager.alert("提示","保存成功","info");
			});
		}
		$scope.isAlarmUserSelected = function(){
			
		}
		$scope.addUserToAlarmItem = function(user,alarmItem){
			alarmItem.users.push(user);
		}
		$("#pollAlarmData").idTabs();
		/**
		 * 界面新增报警阀值集合
		 */
		$scope.NewPollAlarmList=[];
		/**
		 * 新增一个污染物阀值
		 */
		$scope.isShowAddBtn="true";
		$scope.addNewPollAlarm = function(){
			$scope.NewPollAlarmList.push({});
			$scope.isShowAddBtn="false";
		};
		//关闭污染物阈值新增窗口
		$scope.closeAddWryData=function(){
			//清空已选择的角色和用户
			$scope.selectedUsers="";
			$scope.allRoles="";
			//清空新增集合
			$scope.NewPollAlarmList=[];
			$itfreer.closeWindow('add_poll_alarm_thred');
		};
		/**
		 * 显示指派页面
		 */
		$scope.showAlarmAssignDiv = function() {
			$scope.IsShowRoleUser='true';
			$scope.IsShowAlarmThreshold='false';
		}
		/**
		 * 隐藏指派页面
		 */
		$scope.hideAlarmAssignDiv = function() {
			$scope.IsShowRoleUser='false';
			$scope.IsShowAlarmThreshold='true';
		}
		/**
		 * 确定按钮
		 */
		$scope.onSureClick = function () {
			$scope.IsShowRoleUser='false';
			$scope.IsShowAlarmThreshold='true';
		}
		/**
		 * 对输入的下限值进行判断，是否大于上限值
		 */
		$scope.compareWithUpLimit=function(upLimit,downLimit) {
			var reg = /^[0-9]+$/;
			if(upLimit!="" && !reg.test(downLimit)) {
				$.messager.alert("提示","请输入数字");
				return;
			}
			if(downLimit!=null&&upLimit!=null) {
				if(parseFloat(upLimit)<parseFloat(downLimit)) {
					$.messager.alert("提示","下限值不能大于上限值");
				}
			}
		}
		/**
		根据GUID删除对应的数据
		 */
		$scope.deletePollAlarmInfo=function(curRow) {
			var GUID = curRow.GUID;
			$waterDataCommon.post("/OnlineMonitor/deletePollAlarmByGUID",{"GUID":GUID},function(){
				$.messager.alert("提示","删除成功！");
				$scope.getStationWryAlarmInfoByExpNo($scope.stationID,"");
			});
		}
	});
}(window, angular));	